package producer;

import com.gitee.kamismile.stone.rpc.core.provider.producer.StoneRpcReference;
import com.gitee.kamismile.stone.rpc.grpc.common.GrpcCommonProto.ResultDTO;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.protobuf.InvalidProtocolBufferException;
import com.hans.grpcserver.grpc.GreeterGrpc;
import com.hans.grpcserver.grpc.HelloProto;
import com.hans.grpcserver.grpc.HelloProto.HelloReply;
import com.hans.grpcserver.grpc.StoneGreeterGrpc;
import io.grpc.BindableService;
import org.springframework.stereotype.Component;

import java.util.concurrent.ExecutionException;

@Component
public class DD {

    @StoneRpcReference(retry = 0,timeout = 50000)
    private StoneGreeterGrpc.Greeter ic;

    public void aa(String name) throws InvalidProtocolBufferException {
        HelloProto.HelloRequest helloRequest=HelloProto.HelloRequest.newBuilder().setName(name).build();
        ResultDTO aa = ic
            .sayHello(helloRequest);
        System.out.println("----------------");
        System.out.println(aa.getData().unpack(HelloProto.HelloReply.class).getMessage());
    }

    public void bb(String name) throws ExecutionException, InterruptedException {
        HelloProto.HelloRequest helloRequest=HelloProto.HelloRequest.newBuilder().setName(name).build();
        ListenableFuture<ResultDTO> aa = ic.sayByeAsync(helloRequest);
        System.out.println(aa.get().getMessage());
    }
}
